import React, { Component } from 'react';

class App extends Component {
    constructor(porps){
        super(porps);
        //1.创建一个引用
        this.inputRef = React.createRef();
    }
    handleClick =(params) => {
       this.inputRef.current.focus()
    }
    render() {
        return (
            <div>
                {/* 2.绑定引用到元素 */}
                <input type="text" ref={this.inputRef}/>
                <button onClick={this.handleClick}>自动聚焦</button>
            </div>
        );
    }
}

export default App;
